<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
          { name: 'box-ys', title: '验收信息' },
          { name: 'box-ywb', title: '保修维修信息' },
          { name: 'box-use', title: '使用信息' },
          { name: 'box-file', title: '设备附件' },
        ]"
      />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly || cpIsLock">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="设备名称" name="deviceName" :parent="_self" :form="form"/>
          <customFormItem label="品牌" name="deviceBrand" :parent="_self" :form="form"/>
          <customFormItem label="设备编码" name="deviceCode" :parent="_self" :form="form"/>
          <customFormItem label="原设备编码" name="codeOriginal" :parent="_self" :form="form"/>

          <customFormItem label="设备状态" name="deviceStatus" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.deviceRunStatus}"
          />

          <customFormItem label="规格型号" name="deviceSpec" :parent="_self" :form="form"/>

          <customFormItem label="单位" name="deviceUnit" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.deviceUnit}"
          />

          <customFormItem label="月折旧率" name="deviceDepreciation" :parent="_self" :form="form"
                          :type="constCommon.formItemType.inputNumber.name"
                          :config="{step: 0.0002,decimalPlaces:4, max: 100, format: (value) => `${value} %`}"
          />

          <customFormItem label="单价" name="devicePrice" :parent="_self" :form="form"
                          :type="constCommon.formItemType.inputNumber.name"
          />

          <customFormItem label="标签码" name="deviceSn" :parent="_self" :form="form"/>

          <customFormItem label="寿命年限" name="deviceLife" :parent="_self" :form="form"
                          :type="constCommon.formItemType.inputNumber.name"/>

          <customFormItem label="进口设备" name="flagImport" :parent="_self" :form="form"
                          :type="constCommon.formItemType.switch.name"/>

          <div id="box-ys" class="box-title">验收信息</div>
          <customFormItem
            label="供应商"
            name="supplierName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.supplier(supplierSelect)"
          />
          <customFormItem label="供应商联系电话" name="supplierPhone" :parent="_self" :form="form"/>

          <customFormItem
            label="厂商"
            name="mfgName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.mfg(mfgSelect)"
          />
          <customFormItem label="出厂日期" name="deviceMfgDate" :parent="_self" :form="form"
                          :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="验收人" name="personAccept" :parent="_self" :form="form"/>
          <customFormItem label="验收日期" name="deviceAcceptDate" :parent="_self" :form="form"
                          :type="constCommon.formItemType.datePicker.name"/>

          <div id="box-ywb" class="box-title">保修维修信息</div>
          <customFormItem label="保修中" name="flagWarranty" :parent="_self" :form="form"
                          :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="保修截止" name="warrantyDateEnd" :parent="_self" :form="form"
                          :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="维修公司" name="repairCompany" :parent="_self" :form="form"/>
          <customFormItem label="维修公司电话" name="repairCompanyPhone" :parent="_self" :form="form"/>
          <customFormItem label="维修日期" name="repairDate" :parent="_self" :form="form"
                          :type="constCommon.formItemType.datePicker.name"/>

          <div id="box-use" class="box-title">使用信息</div>
          <customFormItem label="启用日期" name="deviceEnableDate" :parent="_self" :form="form"
                          :type="constCommon.formItemType.datePicker.name"/>
          <customFormItem label="采购单编码" name="poCode" :parent="_self" :form="form"/>

          <customFormItem label="采购合同编码" name="contractCode" :parent="_self" :form="form"/>

          <customFormItem label="维保合同编码" name="repairContractCode" :parent="_self"
                          :form="form"/>

<!--          <customFormItem
            label="管理科室"
            name="deptNameManage"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(deptNameManageChange)"
          />-->

          <customFormItem
            label="所属科室"
            name="deptNameOwner"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(deptNameOwnerChange)"
            help="设备采购科室"
          />

          <customFormItem
            label="使用科室"
            name="deptNameUse"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.dept(deptNameUseChange)"
            help="当前使用科室"
          />

          <customFormItem
            label="设备分类"
            name="categoryName"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="$refs.tableDrawerCategory.show()"
          />

          <customFormItem label="锁定" name="flagLock" :parent="_self" :form="form"
                          :type="constCommon.formItemType.switch.name" disabled/>

          <customFormItem label="锁定信息" name="lockInfo" :parent="_self" :form="form"  disabled/>

          <div id="box-file" class="box-title">设备附件</div>
          <customFormItem
            label=""
            name="deviceFile"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.slot.name"
            fullWidth
          >
            <template #content>
              <customUpload
                :data="{ fileRefId: form.id, fileRefTable: 'device_ledger', fileSavePath: 'device_ledger'}"
                :hide="strings.isBlank(form.id)"
                hideMsg="请先保存主单据后再上传"
                :max="20"
                :disabled="propReadonly"
                multiple
              />
            </template>
          </customFormItem>

        </template>
      </customForm>
    </div>

    <!--分类选择-->
    <tableDrawer ref="tableDrawerCategory" refName="tableDrawerCategory" attach="body"
         @confirm="categoryConfirm"  :viewKey="constCommon.viewKeySelect.matrCategory"/>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'
import customUpload from "@/components/custom/form/customUpload.vue";

export default {
  desc: '设备台账-详情',
  data() {
    return {
      form: {},
    }
  },
  computed: {
    cpIsLock() {
      return true == this.form.flagLock
    }
  },
  created() {
    this.$emit('event-register', {
      //表单校验
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },

      //保存前操作
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },

      //数据加载后
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        if (this.cpIsLock) {
          setTimeout(() => {
            this.utilMessage.warning('当前设备已被锁定，暂不可修改')
          }, 2000)
        }
      },

      //数据保存后
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },

      //数据删除后
      afterDelete: () => {
      },

      //流程提交前
      beforeFlow: (flowButtonKey) => {
        return true
      },

      //流程提交后
      afterFlow: (flowButtonKey) => {
      },

      //表单关闭前
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    //上级对象
    propParent: Object,
    //上级初始化数据
    propInitData: Object,
    //主键字段
    propPrimaryKey: String,
    //数据字典
    propDictionaries: Object,
    //当前操作行
    propCurrentRow: Object,
    //表单数据
    propViewFormData: Object,
    //是否只读
    propReadonly: Boolean,
    //操作状态
    propStatus: String,
    //表单规则
    propRules: Object
  },
  components: {
    customUpload,
    customAnchor
  },
  methods: {
    //供应商选择
    supplierSelect(row, refName) {
      this.$set(this.form, 'supplierId', row.id)
      this.$set(this.form, 'supplierName', row.name)
    },
    //厂商选择
    mfgSelect(row, refName) {
      this.$set(this.form, 'mfgId', row.id)
      this.$set(this.form, 'mfgName', row.name)
    },
    // 管理科室选择
    deptNameManageChange(item) {
      this.$set(this.form, 'deptIdManage', item.id)
      this.$set(this.form, 'deptNameManage', item.name)
    },
    // 所属科室选择
    deptNameOwnerChange(item) {
      this.$set(this.form, 'deptIdOwner', item.id)
      this.$set(this.form, 'deptNameOwner', item.name)
    },
    //使用科室选择
    deptNameUseChange(item) {
      this.$set(this.form, 'deptIdUse', item.id)
      this.$set(this.form, 'deptNameUse', item.name)
    },
    //分类选择
    categoryConfirm(item) {
      this.$set(this.form, 'categoryId', item.id)
      this.$set(this.form, 'categoryName', item.categoryName)
    }
  }
}
</script>
